package com.cci.kangdao.utilTool;

import java.util.Random;

/**
 * @author William Du
 * @date 2019/10/9
 */
public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils {


    public static boolean isPositiveNum(Long num) {
        if (null != num && num > 0L) {
            return true;
        }
        return false;
    }

    public static boolean isPositiveNum(Integer num) {
        if (null != num && num > 0) {
            return true;
        }
        return false;
    }

    public static boolean isNatural(Long num) {
        if (null != num && num >= 0L) {
            return true;
        }
        return false;
    }

    public static boolean isNatural(Integer num) {
        if (null != num && num >= 0) {
            return true;
        }
        return false;
    }

    //length为生成几位数密码   需要规避字母：i/I/o/O/l    数字：1/0
    public static String getStringRandom(int length){
        String val = "";
        Random random = new Random();
        //是否存在大写字母(0:否    1:是)
        int isHaveUpperCase = 0;
        //是否存在小写字母(0:否    1:是)
        int isHaveLowerCase = 0;
        //是否存在数字(0:否    1:是)
        int isHaveNum = 0;
        for(int i = 0; i < length; i++) {
            if(isHaveUpperCase == 0){
                int n = random.nextInt(26) + 65;
                if(n == 73 || n == 79){//不要I,O
                    n++;
                }
                val += (char)(n);
                isHaveUpperCase = 1;
                continue;
            }
            if(isHaveLowerCase == 0){
                int n = random.nextInt(26) + 97;
                if(n == 105 || n == 108 || n == 111){//不要i,l,o
                    n++;
                }
                val += (char)(n);
                isHaveLowerCase = 1;
                continue;
            }
            if(isHaveNum == 0){
                int n = random.nextInt(10);
                if(n == 0 || n == 1){//不要0 和 1
                    n += 2;
                }
                val += String.valueOf(n);;
                isHaveNum = 1;
                continue;
            }
            int charOrNum = random.nextInt(3) ;
            if( 0 == charOrNum) {   //拼接大写字母
                int n = random.nextInt(26) + 65;
                if(n == 73 || n == 79){//不要I,O
                    n++;
                }
                val += (char)(n);
            }else if( 1 == charOrNum) {   //拼接小写字母
                int n = random.nextInt(26) + 97;
                if(n == 105 || n == 108 || n == 111){//不要i,l,o
                    n++;
                }
                val += (char)(n);
            } else if( 2 == charOrNum) {   //拼接数字
                int n = random.nextInt(10);
                if(n == 0 || n == 1){//不要0 和 1
                    n += 2;
                }
                val += String.valueOf(n);
            }
        }
        return val;
    }

}
